Skip to content

Allow PAT-authenticated clients to create shares via JSON API#36

Merged
etagwerker merged 1 commit into
mainfrom
api-create-share
May 16, 2026
Merged

Allow PAT-authenticated clients to create shares via JSON API#36
etagwerker merged 1 commit into
mainfrom
api-create-share

Conversation

@etagwerker
Copy link
Copy Markdown
Member

Summary

  • Adds POST /links/:link_id/shares.json so a user holding a personal access token can create shareable links for a link, paired with the existing GET /links/:link_id/shares.json for querying them.
  • SharesController#create now responds to both HTML and JSON (returns 201 Created with the share payload, or 422 with errors).
  • The shortened-URL assignment is rescued so a Rebrandly outage doesn't leak a 500 after the share is already persisted; the API simply returns the share with a null shortened_url and a warning is logged.

Test plan

  • bundle exec rspec — 38 examples, 0 failures
  • Manually curl -X POST -H "Authorization: Bearer <token>" -H "Accept: application/json" -d 'share[utm_source]=...' /links/<id>/shares.json and confirm a 201 response with the share JSON
  • Confirm that a non-JSON request still redirects to the link page with the success flash (HTML flow unchanged)
  • Confirm that a request without a Bearer token returns 401

🤖 Generated with Claude Code

Adds POST /links/:link_id/shares.json to the JSON API so a user
holding a personal access token can create shareable links for a
link (paired with the existing GET endpoint for querying them).

- whitelist shares#create in API_ENDPOINTS
- SharesController#create now responds to JSON with 201/422
- shortened_url assignment is rescued so a Rebrandly failure
  doesn't leak a 500 after the share is already persisted
- request specs cover success, validation errors, auth, and the
  shorten-failure path

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@etagwerker etagwerker merged commit 82b5785 into main May 16, 2026
1 check passed
@etagwerker etagwerker deleted the api-create-share branch May 16, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant